package com.etc.dao.impl;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.etc.dao.CollectionDao;
import com.etc.entity.Collection;
import com.etc.util.DBUtil;

public class CollectionDaoImpl implements CollectionDao{
	/**
	 * 添加一条收藏记录
	 */
	@Override
	public int add(Integer customerId, Integer gamesId) {
		return DBUtil.update("insert into collection(customer_id,games_id) value(?,?)", customerId, gamesId);
	}
	/**
	 * 查询单个收藏
	 */
	@Override
	public Collection findByCustomerIdAndGamesId(Integer customerId, Integer gamesId) {
		ResultSet rs = DBUtil.query("select collection_id from collection where customer_id = ? and games_id = ?", customerId, gamesId);
		Collection collection = null;
		try {
			while (rs.next()) {
				Integer collectionId = rs.getInt("collection_id");  
				collection = new Collection();
				collection.setCollectionId(collectionId);
				collection.setCustomerId(customerId);
				collection.setGamesId(gamesId);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return collection;
	}
	/**
	 * 删除单个收藏
	 */
	@Override
	public int deleteByCustomerIdAndGamesId(Integer customerId, Integer gamesId) {
		
		return DBUtil.update("delete from collection where customer_id = ? and games_id = ?", customerId, gamesId);
	}

}
